package cn.yu.meeting.meeting.service;

import cn.yu.meeting.common.pojo.PageBean;
import cn.yu.meeting.common.utils.ThreadLocalUtil;
import cn.yu.meeting.meeting.mapper.MeetingMapper;
import cn.yu.meeting.meeting.pojo.Meeting;
import cn.yu.meeting.meeting.pojo.MeetingListItem;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class MeetingService {
    @Autowired
    MeetingMapper meetingMapper;

    /**
     * 获取会议列表
     *
     * @param pageNum  页码
     * @param pageSize 每页数量
     * @return 会议列表
     */
    public PageBean<MeetingListItem> getMeetingList(Integer pageNum, Integer pageSize) {
        PageBean<MeetingListItem> pageBean = new PageBean<>();
        PageHelper.startPage(pageNum, pageSize);
        // 补充人员信息
        Map<String, Object> claims = ThreadLocalUtil.get();
        Integer userId = (Integer) claims.get("id");
        List<MeetingListItem> meetingList = meetingMapper.getMeetingList(userId);
        //Page 中提供了方法,可以获取PageHelper 分页查询后,得到的总记录条数,he当前页数
        Page<MeetingListItem> page = (Page<MeetingListItem>) meetingList;
        pageBean.setTotal(page.getTotal());
        pageBean.setItems(page.getResult());
        return pageBean;
    }

    /**
     * 添加会议
     * @param tittle    会议标题
     * @param desc     会议描述
     * @param startTime 开始时间
     * @param endTime  结束时间
     */
    public void addMeeting(String tittle, String desc, String startTime, String endTime) {
//        meetingMapper.addMeeting(tittle, desc, LocalDateTime.now(), LocalDateTime.now());
    }

}
